﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
//using Chefbook.DataObjects;
using Chefbook.HelperMethods;

namespace Chefbook.DataObjects
{
    /// <summary>
    /// Represents an Ingredient in a Recipe
    /// Ingredients are represented as [Amount][Units][Name]
    /// Examples: [1][ ][Apple], [3.5][Tablespoon][Brown sugar]
    /// </summary>
    public class Ingredient
    {
        private float amount;
        private string name, units;
        /// <summary>
        /// Gets or sets the name of the ingredient
        /// </summary>
        public string Name 
        {
            get { return name; }
            set { name = value.ThrowIfNull("Name"); }
        }

        /// <summary>
        /// Gets or sets the amount of the ingredient, specified in the listed units.  Use zero for "To taste"
        /// </summary>
        public float Amount {
            get { return amount; }
            set
            {
                ParameterValidation.ValidateArgument(() => value >= 0, "Amount");
                amount = value;
            }
        }

        /// <summary>
        /// Gets or sets the units this ingredient is measured in.  May be String.Empty if representing whole things, such as an apple
        /// </summary>
        public string Units
        {
            get { return units; }
            set { units = value.ThrowIfNull("Units"); }
        }

        public Recipe Recipe { get; private set; }

        /// <summary>
        /// Do not create directly.  Use Recipe.AddNewIngredient()
        /// </summary>
        /// <param name="recipeContainingIngredient">The recipe this ingredient is added to</param>
        internal Ingredient(Recipe recipeContainingIngredient)
        {
            name = string.Empty;
            units = string.Empty;
            Recipe = recipeContainingIngredient.ThrowIfNull("recipeContainingIngredient");
            
        }
    }
}
